package com.coderman.basketball.statistics.service;

import com.coderman.basketball.statistics.context.CalculateContextBO;
import com.coderman.basketball.statistics.context.DataBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Description:
 * date: 2021/5/27
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 * 分数计算服务
 * 球队分数
 * 球员分数
 */
@CalculateTag(calculateType = "score")
@Component(value = "scoreCalculateServiceImpl")
public class ScoreCalculateServiceImpl implements CalculateService{

    @Autowired
    private DataService dataService;

    @Override
    public void calculate(CalculateContextBO calculateBO) {
        if(calculateBO.isIncr()){
            DataBO dataBO = new DataBO();
            dataBO.setGameId(calculateBO.getGameId());
            dataBO.setCount(calculateBO.getCount());
            dataBO.setKey(calculateBO.getActionKey());
            dataBO.setPlayerId(calculateBO.getPlayerId());
            dataService.updateDataKey(dataBO);
        }else {
            DataBO dataBO = new DataBO();
            dataBO.setGameId(calculateBO.getGameId());
            dataBO.setCount(0-calculateBO.getCount());
            dataBO.setPlayerId(calculateBO.getPlayerId());
            dataBO.setKey(calculateBO.getActionKey());
            dataService.updateDataKey(dataBO);
        }
    }
}
